package collection3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/*Collection工具类的使用

 */
public class Demo04 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(24);
        list.add(77);
        list.add(10);
        list.add(23);
        list.add(30);
        //sort排序
        System.out.println("排序之前：" + list.toString());
        Collections.sort(list);
        System.out.println("排序之前：" + list.toString());
        //binarySearch 大于0 表示找到了 小于0表示没有找到
        int n1 = Collections.binarySearch(list, 24);
        int n2 = Collections.binarySearch(list, 13);
        System.out.println(n1);
        System.out.println(n2);
//         List<Integer> dest =  new ArrayList<Integer>(list.size());
//        for (int i = 0; i < list.size(); i++) {
//            dest.add(0);
//        }
        List<Integer> dest = Arrays.asList(new Integer[list.size()]);
        Collections.copy(dest,list);
        System.out.println(dest.toString());
        //reverse反转
        Collections.reverse(list);
        System.out.println("反转之后：" + list.toString());
        //shuffle 打乱
        Collections.shuffle(list);
        System.out.println("打乱之后：" + list.toString());
        //list转成数组
        Integer[] arr = list.toArray(new Integer[0]);
        System.out.println(arr.length);
        System.out.println(Arrays.toString(arr));
        //数组转成集合
        String[] names = {"张三", "李四","王五" };
        List<String> list2 = Arrays.asList(names);
        System.out.println(list2);
        //注意：数组转成集合后不能添加和删除

    }
}
